//==================客户端======================
const dateKit = require( "./util/dateKit");
const dataKit = require( "./util/dataKit");
const util = require( "./util/util")
const clientService = require( "./util/clientService")

/**
 * 登录
 * userNick 用户昵称
 */
exports.login = async (context) => {
    const {userNick} = context.data;
    const {openId,appOwnerOpenId} = context;

    if(!userNick){
        return {code:-1,msg:"userNick不能为空"}
    }
    
    let userInfo = await clientService.getUserByOpenId(context,openId);
    if(!userInfo){
        userInfo = {openId:openId,
                    createTime:dateKit.getCurrentDateTime()};
    }
    
    userInfo.appOwnerOpenId=appOwnerOpenId;
    userInfo.userNick=userNick;
    userInfo.loginTime = dateKit.getCurrentDateTime();
    const result = await dataKit.insertOrUpdate(context,"user_info",userInfo);
    
    return {code:0,msg:"登录成功"};
};

/**
 * 获取商品列表
 */
exports.getProductList = async (context) => {
    let result = await clientService.getProductList(context);
    return {code:0,msg:"获取成功",data:result};
};

/**
 * 会员身份识别
 */
exports.isTaobaoMember = async (context) => {
    let result = await clientService.isTaobaoMember(context,context.mixNick);
    return {code:0,msg:"获取成功",data:result};
};